<?php

require_once (dirname(__FILE__) . "/include/common.inc.php");
require_once DEDEINC."/arc.partview.class.php";

if(empty($id)) //检测是否使用推广
{//检测是否使用推广

	$GLOBALS['_arclistEnv'] = 'index';
	$row = $dsql->GetOne("Select * From `#@__homepageset`");
	$row['templet'] = MfTemplet($row['templet']);
	$pv = new PartView();
	$pv->SetTemplet($cfg_basedir . $cfg_templets_dir . "/" . $row['templet']);
	$pv->Display();
	/*
	//自动生成HTML版
	if(isset($_GET['upcache']))
	{
		require_once (dirname(__FILE__) . "/include/common.inc.php");
		require_once DEDEINC."/arc.partview.class.php";
		$GLOBALS['_arclistEnv'] = 'index';
		$row = $dsql->GetOne("Select * From `#@__homepageset`");
		$row['templet'] = MfTemplet($row['templet']);
		echo $row['templet'];
		$pv = new PartView();
		$pv->SetTemplet($cfg_basedir . $cfg_templets_dir . "/" . $row['templet']);
		$pv->SaveToHtml(dirname(__FILE__).'/index.html');
		include(dirname(__FILE__).'/index.html');
		exit();
	}
	else
	{
		header('HTTP/1.1 301 Moved Permanently');
		header('Location:index.html');
	}
	*/
	
	


}//检测是否使用推广
else
{//检测是否使用推广
//检测IP开始
	if ($_SERVER["HTTP_X_FORWARDED_FOR"]) {
		/*if ($_SERVER["HTTP_CLIENT_IP"]) {
			$proxy = $_SERVER["HTTP_CLIENT_IP"];
		} else {
			$proxy = $_SERVER["REMOTE_ADDR"];
		}*/
		$ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
	} else {
		if ($_SERVER["HTTP_CLIENT_IP"]) {
			$ip = $_SERVER["HTTP_CLIENT_IP"];
		} else {
		$ip = $_SERVER["REMOTE_ADDR"];
	}
}

//判断是否有代理IP
if (isset($proxy)) {
	//ShowMsg("请不要使用代理IP!", 'index.php');
}

//检测IP结束
//以上只检测一个IP
else
{


	//写入数据开始
	$sql = "Select userid from #@__tgreg where userid='$id'"; 
	$NIC_arcRow = $dsql->GetOne($sql);  
	if(empty($userid)) $username =$NIC_arcRow['userid'];  
	
	
	//检测IP是否重复
	$row = $dsql->GetOne("Select * From `#@__tgip` where userid='$id' and tgip like '$ip' ");
	if(is_array($row)){
	    header('location:index.php');//IP重复就跳转
		exit();
	}

	$tgip = $ip;
	$time =time();//获取时间
	$lailu ="无";//获取来路
	//写入数据结束
	//$query = "insert into `#@__tgip`(userid, username, time) values ('$cfg_ml->M_ID', '$cfg_ml->M_UserName', '$time'); ";
	if(empty($username)) 
	{
	    header('location:index.php');
		exit;
	} 

	$query = "insert into `#@__tgip`(userid, username, time, tgip, lailu) values ('$id', '$username', '$time', '$ip', '$lailu'); ";
	if($dsql->ExecuteNoneQuery($query)){
	
		$jifen = $cfg_userad_adds; //设置推荐一个增加多少积分
		$dsql->ExecuteNoneQuery("update `#@__member` set `scores`= scores + $jifen  where mid='".$id."' ");
		header('location:index.php');
	}else{
	    header('location:index.php');
	}
	exit();
}














}//检测是否使用推广
?>